class Solution(object):
    def reverseOnlyLetters(self, s):
        """
        :type s: str
        :rtype: str
        """
        c = list(s)
        n = len(c)
        left = 0
        right = n - 1
        while left < right:
            if not ('a' <= s[left] <= 'z' or 'A' <= s[left] <= 'Z'):
                left += 1
            else:
                if not ('a' <= s[right] <= 'z' or 'A' <= s[right] <= 'Z'):
                    right -= 1
                else:
                    c[left], c[right] = c[right], c[left]
                    left += 1
                    right -= 1
        return ''.join(c)



